package org.zpmis.api.http;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.domain.file.service.FileService;
import org.zpmis.domain.mail.model.SimpleMailMessageParam;
import org.zpmis.domain.mail.service.MailService;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@RestController
public class MessageController {

    @Reference
    private FileService fileService;

    @Reference
    private MailService mailService;

    @GetMapping("/sendEmail")
    public String sendEmail(){
        try {
            byte[] bytes = fileService.get("7368324793434e93803fcd4dee54ee5e.pdf", "defaut");

            Map<String,String> map = new HashMap<>();
            map.put("orderNumber", "DD202107280001");
            map.put("invoiceDate", LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));

            mailService.sendSimpleMail(new SimpleMailMessageParam("","",""));
            /*mailService.sendThymeleafMail(
                    MailMessageParam.builder()
                            .toEmial("shaoyangyang@cpzs.org")
                            .templateName("Invoice.html")
                            .attachmentFilename("7368324793434e93803fcd4dee54ee5e.pdf")
                            .bytes(Arrays.asList(bytes))
                            .map(map)
                            .subject("发票邮件")
                            .build());*/
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }
}
